package ngat.oss;

import ngat.message.OSS.*;
import ngat.astrometry.*;
import ngat.util.logging.*;
import ngat.phase2.*; 
import ngat.instrument.*;

import java.io.*;

/** 
 * Action: Sets the current Telescope Pointing direction (RA, dec) for the 
 * Scheduling algorithm to use.
 *
 * $Id: TEL_INFOImpl.java,v 1.1 2006/11/27 08:45:00 snf Exp $
 */
public class TEL_INFOImpl extends TransactionImpl implements Logging {

    /** The current azimuth of the telescope (rads).*/
    protected double telescopeAzimuth;

    /** The current altitude of the telescope (rads).*/
    protected double telescopeAltitude;
    
    /** True if the autoguider is currently available.*/
    protected boolean autoguiderAvailable;
    
    /** Telescope azimuth negative wrap limit (rads).*/
    protected double azNegLimit;

    /** Telescope azimuth positive wrap limit (rads).*/
    protected double azPosLimit;

    /** Telescope altitude low limit (rads).*/
    protected double altLowLimit;

    /** Telescope altitude high limit (rads).*/
    protected double altHighLimit;
	
    /** Telescope rot negative wrap limit (rads).*/
    protected double rotNegLimit;

    /** Telescope rot positive wrap limit (rads).*/
    protected double rotPosLimit;
    
    public TEL_INFOImpl(TEL_INFO request) {
	super(request);
	telescopeAzimuth  = request.getTelescopeAzimuth();
	telescopeAltitude = request.getTelescopeAltitude();	
	this.autoguiderAvailable = request.getAutoguiderAvailable();
	this.azNegLimit = request.getAzNegLimit();
	this.azPosLimit = request.getAzPosLimit();
	this.altLowLimit = request.getAltLowLimit();
	this.altHighLimit = request.getAltHighLimit();	
	this.rotNegLimit = request.getRotNegLimit();
	this.rotPosLimit = request.getRotPosLimit();
    }

    /**
     * Set the Telescope's current pointing Position to that specified and
     * update the ag-availability and wrap limits..
     * @return The previous Telescope Pointing direction (RA,dec).
     */
    public TRANSACTION_DONE exec() {
	SkyCoordinate coord = new SkyCoordinate(telescopeAzimuth,telescopeAltitude); 
	TelescopeStatus.setTelescopeAzimuth(telescopeAzimuth);
	TelescopeStatus.setTelescopeAltitude(telescopeAltitude);
	TelescopeStatus.setAutoguiderAvailable(autoguiderAvailable);
	TelescopeStatus.setAzNegLimit(azNegLimit);
	TelescopeStatus.setAzPosLimit(azPosLimit);
	TelescopeStatus.setAltLowLimit(altLowLimit);
	TelescopeStatus.setAltHighLimit(altHighLimit);
	TelescopeStatus.setRotNegLimit(rotNegLimit);
	TelescopeStatus.setRotPosLimit(rotPosLimit);
	
	logger.log(INFO, 1, "TEL_INFO_Impl", id, "exec",
		   "Updated Telescope info to:"+
		   "\n\tAz-Neg-Wrap:  "+Position.toDegrees(azNegLimit, 3)+
		   "\n\tAz-Pos-Wrap:  "+Position.toDegrees(azPosLimit, 3)+
		   "\n\tAlt-Low:      "+Position.toDegrees(altLowLimit, 3)+
		   "\n\tAlt-High:     "+Position.toDegrees(altHighLimit, 3)+
		   "\n\tRot-Neg-Wrap: "+Position.toDegrees(rotNegLimit, 3)+
		   "\n\tRot-Pos-Wrap: "+Position.toDegrees(rotPosLimit, 3)+		 
		   "\n\tAzimuth:      "+Position.toDegrees(telescopeAzimuth, 3)+
		   "\n\tAltitude:     "+Position.toDegrees(telescopeAltitude, 3)+
		   "\n\tAutoGuider:   "+(autoguiderAvailable ? "AVAILABLE" : "NOT AVAILABLE"));

	TEL_INFO_DONE done = new TEL_INFO_DONE(id);
	done.setSuccessful(true);
	return done;

    }

}

/** $Log: TEL_INFOImpl.java,v $
/** Revision 1.1  2006/11/27 08:45:00  snf
/** Initial revision
/**
/** Revision 1.1  2006/11/27 08:37:05  snf
/** Initial revision
/** */
